home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / misc / WHDLoad_dev.lha / WHDLoad / Src / sources / whdload / kick12.s < prev    next >
Encoding:
Text File  |  2003-12-10  |  18.2 KB  |  895 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Modul.    kick12.s
  3. ;  :Contents.    interface code and patches for kickstart 1.2
  4. ;  :Author.    Wepl, JOTD, Psygore
  5. ;  :Version.    $Id: kick12.s 1.16 2003/12/10 14:22:58 wepl Exp wepl $
  6. ;  :History.    17.04.02 created from kick13.s and kick12.s from JOTD
  7. ;        18.11.02 illegal trackdisk-patches enabled if DEBUG
  8. ;        30.11.02 FONTHEIGHT added
  9. ;        13.02.03 snoopbug at $6e92 fixed (Psygore)
  10. ;             STACKSIZE added (Captain HIT)
  11. ;        30.03.03 _bootearly/block made returnable
  12. ;        06.04.03 cache option added
  13. ;        15.05.03 patch for exec.ExitIntr to avoid double ints
  14. ;        11.06.03 patch for access fault from EndCLI (JOTD)
  15. ;        20.06.03 adapted for whdload v16
  16. ;        25.06.03 _dos_assign parameter change
  17. ;        09.12.03 keyboard acknowledgment fixed
  18. ;  :Requires.    -
  19. ;  :Copyright.    Public Domain
  20. ;  :Language.    68000 Assembler
  21. ;  :Translator.    Barfly 2.9, Asm-Pro 1.16, PhxAss 4.38
  22. ;  :To Do.
  23. ;---------------------------------------------------------------------------*
  24.  
  25.     INCLUDE    lvo/exec.i
  26.     INCLUDE    lvo/graphics.i
  27.     INCLUDE    devices/trackdisk.i
  28.     INCLUDE    exec/memory.i
  29.     INCLUDE    graphics/gfxbase.i
  30.  
  31. KICKVERSION    = 33
  32. KICKCRC        = $e9c6                ;33.180
  33.  
  34. ;============================================================================
  35.  
  36.     IFD    slv_Version
  37.     IFNE    slv_Version-16
  38.     FAIL    must be slave version 16
  39.     ENDC
  40.  
  41. KICKSIZE    = $40000            ;33.180
  42. BASEMEM        = CHIPMEMSIZE
  43. EXPMEM        = KICKSIZE+FASTMEMSIZE
  44.  
  45. slv_base    SLAVE_HEADER            ;ws_Security + ws_ID
  46.         dc.w    slv_Version        ;ws_Version
  47.         dc.w    WHDLF_EmulPriv|slv_Flags;ws_flags
  48.         dc.l    BASEMEM            ;ws_BaseMemSize
  49.         dc.l    0            ;ws_ExecInstall
  50.         dc.w    _boot-slv_base        ;ws_GameLoader
  51.         dc.w    slv_CurrentDir-slv_base    ;ws_CurrentDir
  52.         dc.w    0            ;ws_DontCache
  53. _keydebug    dc.b    0            ;ws_keydebug
  54. _keyexit    dc.b    slv_keyexit        ;ws_keyexit
  55. _expmem        dc.l    EXPMEM            ;ws_ExpMem
  56.         dc.w    slv_name-slv_base    ;ws_name
  57.         dc.w    slv_copy-slv_base    ;ws_copy
  58.         dc.w    slv_info-slv_base    ;ws_info
  59.         dc.w    slv_kickname-slv_base    ;ws_kickname
  60.         dc.l    KICKSIZE        ;ws_kicksize
  61.         dc.w    KICKCRC            ;ws_kickcrc
  62.     ENDC
  63.  
  64. ;============================================================================
  65. ; the following is to avoid "Error 86: Internal global optimize error" with
  66. ; BASM, which is caused by "IFD _label" and _label is defined after the IFD
  67.  
  68.     IFND BOOTBLOCK
  69.     IFD _bootblock
  70. BOOTBLOCK = 1
  71.     ENDC
  72.     ENDC
  73.     IFND BOOTDOS
  74.     IFD _bootdos
  75. BOOTDOS = 1
  76.     ENDC
  77.     ENDC
  78.     IFND BOOTEARLY
  79.     IFD _bootearly
  80. BOOTEARLY = 1
  81.     ENDC
  82.     ENDC
  83.     IFND CBDOSLOADSEG
  84.     IFD _cb_dosLoadSeg
  85. CBDOSLOADSEG = 1
  86.     ENDC
  87.     ENDC
  88.  
  89. ;============================================================================
  90.  
  91. _boot        lea    (_resload,pc),a1
  92.         move.l    a0,(a1)                ;save for later use
  93.         move.l    a0,a5                ;A5 = resload
  94.  
  95.     IFD CACHE
  96.     ;enable cache
  97.         move.l    #WCPUF_Base_NC|WCPUF_Exp_CB|WCPUF_Slave_CB|WCPUF_IC|WCPUF_DC|WCPUF_BC|WCPUF_SS|WCPUF_SB,d0
  98.         move.l    #WCPUF_All,d1
  99.         jsr    (resload_SetCPU,a5)
  100.     ENDC
  101.  
  102.     ;relocate some addresses
  103.         lea    (_cbswitch,pc),a0
  104.         lea    (_cbswitch_tag,pc),a1
  105.         move.l    a0,(a1)
  106.  
  107.     ;get tags
  108.         lea    (_tags,pc),a0
  109.         jsr    (resload_Control,a5)
  110.  
  111.     IFND slv_Version
  112.     ;load kickstart
  113.         move.l    #KICKSIZE,d0            ;length
  114.         move.w    #KICKCRC,d1            ;crc16
  115.         lea    (slv_kickname,pc),a0        ;name
  116.         jsr    (resload_LoadKick,a5)
  117.     ENDC
  118.  
  119.     ;patch the kickstart
  120.         lea    (kick_patch,pc),a0
  121.         move.l    (_expmem,pc),a1
  122.         jsr    (resload_Patch,a5)
  123.  
  124.     ;call
  125. kick_reboot    move.l    (_expmem,pc),a0
  126.         jmp    (2,a0)                ;original entry
  127.  
  128. kick_patch    PL_START
  129.         PL_S    $d2,$fe-$d2
  130.         PL_L    $106,$02390002            ;skip LED power off (and.b #~CIAF_LED,$bfe001)
  131.         PL_CW    $132                ;color00 $444 -> $000
  132.         PL_CW    $25a                ;color00 $888 -> $000
  133.     IFD HRTMON
  134.         PL_PS    $286,kick_hrtmon
  135.     ENDC
  136.         PL_PS    $422,exec_flush
  137.         PL_L    $4f4,-1                ;disable search for residents at $f00000
  138.         PL_S    $50C,$514-$50C            ;skip LED power on
  139.         PL_P    $546,kick_detectcpu
  140.         PL_P    $592,kick_detectchip
  141.         PL_P    $5f0,kick_reboot        ;reboot (reset)
  142.         PL_P    $61a,kick_detectfast
  143.         PL_P    $e80,exec_ExitIntr
  144.         PL_P    $1318,exec_snoop1
  145.         PL_PS    $147a,exec_SetFunction
  146.         PL_PS    $1576,exec_MakeFunctions
  147.     IFD MEMFREE
  148.         PL_P    $17ea,exec_AllocMem
  149.     ENDC
  150.         PL_S    $48fc,$4910-$48fc        ;skip disk unit detect
  151.         PL_P    $4a74,disk_getunitid
  152.         PL_S    $4c66,4                ;skip autoconfiguration at $e80000
  153.         PL_PS    $6d04,gfx_vbserver
  154.         PL_PS    $6d1a,gfx_snoop1
  155.         PL_L    $6e92,$08390005            ;snoop bug ('and.w #$20,$DFF01E' -> 'btst #5,$DFF01E')
  156.         PL_PS    $ad9e,gfx_setcoplc
  157.         PL_S    $adc2,6                ;avoid ChkBltWait problem
  158.         PL_S    $af16,$36-$16            ;skip color stuff & strange gb_LOFlist set
  159.         PL_P    $afe4,gfx_detectgenlock
  160.         PL_P    $b058,gfx_detectdisplay
  161.         PL_PS    $d5cc,gfx_fix1            ;gfx_LoadView
  162.     IFD FONTHEIGHT
  163.         PL_B    $1bc70,FONTHEIGHT
  164.     ENDC
  165.     IFD BLACKSCREEN
  166.         PL_C    $1bcd6,6            ;color17,18,19
  167.         PL_C    $1bcde,8            ;color0,1,2,3
  168.     ENDC
  169.     IFD POINTERTICKS
  170.         PL_W    $1bcdc,POINTERTICKS
  171.     ENDC
  172.         PL_PS    $2572e,keyboard_start
  173.         PL_PS    $25846,keyboard_end
  174.     IFD HDINIT
  175.         PL_PS    $288e8,hd_init            ;enter while starting strap
  176.     ENDC
  177.     IFD BOOTEARLY
  178.         PL_PS    $28986,kick_bootearly
  179.     ELSE
  180.     ENDC
  181.     IFD BOOTBLOCK
  182.         PL_PS    $28a2c,kick_bootblock        ;a1=ioreq a4=buffer a6=execbase
  183.     ENDC
  184.         PL_P    $29308,timer_init
  185.         PL_P    $2998c,trd_task
  186.         PL_P    $2a07a,trd_format
  187.         PL_P    $2a462,trd_motor
  188.         PL_P    $2a734,trd_readwrite
  189.         PL_PS    $2aa56,trd_protstatus
  190.     IFD DEBUG
  191.         PL_L    $29fd4,-1            ;disable asynchron io
  192.         PL_I    $2a51c                ;empty dbf-loop in trackdisk.device
  193.         PL_I    $2aa14                ;trd_seek
  194.         PL_I    $2b2e8                ;trd_rawread
  195.         PL_I    $2b2ee                ;trd_rawwrite
  196.     ENDC
  197.         PL_PS    $342ec,dos_init
  198.         PL_PS    $35a0c,dos_endcli
  199.         PL_PS    $3717c,dos_LoadSeg
  200.     IFD BOOTDOS
  201.         PL_PS    $38a4a,dos_bootdos
  202.     ENDC
  203.     IFD STACKSIZE
  204.         PL_L    $38ac0,STACKSIZE/4
  205.     ENDC
  206.         PL_PS    $3c9b2,dos_1
  207.     ;the following stuff is from SetPatch 1.38
  208.     IFD SETPATCH
  209.         PL_P    $1174,exec_UserState
  210.         PL_P    $165a,exec_FindName
  211.         PL_P    $191e,exec_AllocEntry
  212.         PL_PS    $57c0,gfx_MrgCop
  213.         PL_PS    $7f26,gfx_SetFont
  214.         PL_P    $7f66,gfx_SetSoftStyle
  215.     ENDC
  216.         PL_END
  217.  
  218. ;============================================================================
  219.  
  220. kick_detectfast
  221.     IFEQ FASTMEMSIZE
  222.         sub.l    a4,a4
  223.     ELSE
  224.         move.l    (_expmem,pc),a4
  225.         add.l    #KICKSIZE,a4
  226.         move.l    a4,($1f0-$1ea,a5)
  227.         move.l    a4,($1fc-$1ea,a5)
  228.         add.l    #FASTMEMSIZE,a4
  229.         bsr    _flushcache
  230.     ENDC
  231.         jmp    (a5)
  232.  
  233. kick_detectchip    move.l    #CHIPMEMSIZE,a3
  234.         jmp    (a5)
  235.  
  236.     IFD HRTMON
  237. kick_hrtmon    move.l    a4,d0
  238.         bne    .1
  239.         move.l    a3,d0
  240. .1        sub.l    #8,d0            ;hrt reads too many from stack -> avoid af
  241.         rts
  242.     ENDC
  243.  
  244. kick_detectcpu    move.l    (_attnflags,pc),d0
  245.     IFND NEEDFPU
  246.         and.w    #~(AFF_68881|AFF_68882|AFF_FPU40),d0
  247.     ENDC
  248.         rts
  249.  
  250. exec_ExitIntr    tst.w    (_custom+intreqr)    ;delay to make sure int is cleared
  251.         movem.l    (a7)+,d0-d1/a0-a1/a5-a6
  252.         rte
  253.  
  254.     ;move.w (a7)+,($dff09c) does not work with Snoop/S on 68060
  255. exec_snoop1    move.w    (a7),($dff09c)
  256.         addq.l    #2,a7
  257.         rts
  258.  
  259. exec_MakeFunctions
  260.         subq.l    #8,a7
  261.         move.l    (8,a7),(a7)
  262.         move.l    a3,(4,a7)        ;original
  263.         lea    (_flushcache,pc),a3
  264.         move.l    a3,(8,a7)
  265.         moveq    #0,d0            ;original
  266.         move.l    a2,d1            ;original
  267.         rts
  268.  
  269. exec_SetFunction
  270.         move.l    (a7)+,d1
  271.         pea    (_flushcache,pc)
  272.         move.l    d1,-(a7)
  273.         bset    #1,(14,a1)        ;original
  274.         rts
  275.  
  276. exec_flush    lea    (_custom),a0        ;original
  277.         bra    _flushcache
  278.  
  279.     IFD MEMFREE
  280. exec_AllocMem    movem.l    d0-d1/a0-a1,-(a7)
  281.         move.l    #MEMF_LARGEST|MEMF_CHIP,d1
  282.         jsr    (_LVOAvailMem,a6)
  283.         move.l    (MEMFREE),d1
  284.         beq    .3
  285.         cmp.l    d1,d0
  286.         bhi    .1
  287. .3        move.l    d0,(MEMFREE)
  288. .1        move.l    #MEMF_LARGEST|MEMF_FAST,d1
  289.         jsr    (_LVOAvailMem,a6)
  290.         move.l    (MEMFREE+4),d1
  291.         beq    .4
  292.         cmp.l    d1,d0
  293.         bhi    .2
  294. .4        move.l    d0,(MEMFREE+4)
  295. .2        movem.l    (a7)+,d0-d1/a0-a1
  296.         movem.l    (a7)+,d2-d3/a2
  297.         rts
  298.     ENDC
  299.  
  300.     IFD SETPATCH
  301.  
  302. exec_AllocEntry    movem.l    d2/d3/a2-a4,-(sp)
  303.         movea.l    a0,a2
  304.         moveq    #0,d3
  305.         move.w    (14,a2),d3
  306.         move.l    d3,d0
  307.         lsl.l    #3,d0
  308.         addi.l    #$10,d0
  309.         move.l    #$10000,d1
  310.         jsr    (-$C6,a6)
  311.         movea.l    d0,a3
  312.         movea.l    d0,a4
  313.         tst.l    d0
  314.         beq.b    .BD0
  315.         move.w    d3,(14,a3)
  316.         lea    ($10,a2),a2
  317.         lea    ($10,a3),a3
  318.         moveq    #0,d2
  319. .B78        move.l    (0,a2),d1
  320.         move.l    (4,a2),d0
  321.         move.l    d0,(4,a3)
  322.         beq.b    .B8E
  323.         jsr    (_LVOAllocMem,a6)
  324.         tst.l    d0
  325.         beq.b    .BA4
  326. .B8E        move.l    d0,(0,a3)
  327.         addq.l    #8,a2
  328.         addq.l    #8,a3
  329.         addq.w    #1,d2
  330.         subq.l    #1,d3
  331.         bne.b    .B78
  332.         move.l    a4,d0
  333. .B9E        movem.l    (sp)+,d2/d3/a2-a4
  334.         rts
  335.  
  336. .BA4        subq.w    #1,d2
  337.         bmi.b    .BB8
  338.         subq.l    #8,a3
  339.         movea.l    (0,a3),a1
  340.         move.l    (4,a3),d0
  341.         jsr    (_LVOFreeMem,a6)
  342.         bra.b    .BA4
  343.  
  344. .BB8        moveq    #0,d0
  345.         move.w    (14,a4),d0
  346.         lsl.l    #3,d0
  347.         addi.l    #$10,d0
  348.         movea.l    a4,a1
  349.         jsr    (_LVOFreeMem,a6)
  350.         move.l    (0,a2),d0
  351. .BD0        bset    #$1F,d0
  352.         bra.b    .B9E
  353.  
  354. exec_UserState    move.l    (sp)+,d1
  355.         move.l    sp,usp
  356.         movea.l    d0,sp
  357.         movea.l    a5,a0
  358.         lea    (.B18,pc),a5
  359.         jmp    (_LVOSupervisor,a6)
  360.  
  361. .B18        movea.l    a0,a5
  362.         move.l    d1,(2,sp)
  363.         andi.w    #$DFFF,(sp)
  364.         rte
  365.  
  366. exec_FindName    move.l    a2,-(sp)
  367.         movea.l    a0,a2
  368.         move.l    a1,d1
  369.         move.l    (a2),d0
  370.         beq.b    .FDC
  371. .FBE        movea.l    d0,a2
  372.         move.l    (a2),d0
  373.         beq.b    .FDC
  374.         tst.l    (10,a2)
  375.         beq.b    .FBE
  376.         movea.l    (10,a2),a0
  377.         movea.l    d1,a1
  378. .FD0        cmpm.b    (a0)+,(a1)+
  379.         bne.b    .FBE
  380.         tst.b    (-1,a0)
  381.         bne.b    .FD0
  382.         move.l    a2,d0
  383. .FDC        movea.l    d1,a1
  384.         movea.l    (sp)+,a2
  385.         rts
  386.  
  387.     ENDC
  388.  
  389.     IFD BOOTEARLY
  390. kick_bootearly    movem.l    d0-a6,-(a7)
  391.         bsr    _bootearly
  392.         movem.l    (a7)+,d0-a6
  393.         lea    ($2c,a5),a1        ;original
  394.         moveq    #0,d0            ;original
  395.         rts
  396.     ENDC
  397.  
  398.     IFD BOOTBLOCK
  399. kick_bootblock    movem.l    d2-d7/a2-a6,-(a7)
  400.         bsr    _bootblock
  401.         movem.l    (a7)+,d2-d7/a2-a6
  402.         tst.l    d0            ;original
  403.         rts
  404.     ENDC
  405.  
  406. ;============================================================================
  407.  
  408. gfx_vbserver    lea    (_cbswitch_cop2lc,pc),a6
  409.         move.l    d0,(a6)
  410.         lea    ($bfd000),a6        ;original
  411.         rts
  412.  
  413. _cbswitch    move.l    (_cbswitch_cop2lc,pc),(_custom+cop2lc)
  414.         jmp    (a0)
  415.  
  416.     ;move (custom),(cia) does not work with Snoop/S on 68060
  417. gfx_snoop1    move.b    (vhposr,a0),d0
  418.         move.b    d0,(ciatodlow,a6)
  419.         rts
  420.  
  421. gfx_detectgenlock
  422.         moveq    #0,d0
  423.         rts
  424.  
  425. gfx_detectdisplay
  426.         moveq    #4,d0            ;pal
  427.         move.l    (_monitor,pc),d1
  428.         cmp.l    #PAL_MONITOR_ID,d1
  429.         beq    .1
  430.         moveq    #1,d0            ;ntsc
  431. .1        rts
  432.  
  433. gfx_setcoplc    moveq    #-2,d0
  434.         move.l    d0,(a3)+
  435.         move.l    a3,(cop2lc,a4)        ;original
  436.         move.l    a3,(gb_LOFlist,a2)
  437.         move.l    a3,(gb_SHFlist,a2)
  438.         move.l    d0,(a3)+
  439.         clr.w    (color+2,a4)
  440.         add.l    #$adb6-$ad9e-6,(a7)
  441.         rts
  442.  
  443.     ;somewhere there will used a empty view, too stupid
  444. gfx_fix1    move.l    (v_LOFCprList,a0),d0
  445.         beq    .s1
  446.         move.l    d0,a1
  447.         move.l    (4,a1),(gb_LOFlist,a2)
  448. .s1        move.l    (v_SHFCprList,a0),d0
  449.         beq    .s2
  450.         move.l    d0,a1
  451.         move.l    (4,a1),(gb_SHFlist,a2)
  452. .s2        add.l    #$d5e0-$d5cc-6,(a7)
  453.         rts
  454.  
  455.     IFD SETPATCH
  456.  
  457. gfx_MrgCop    move.w    ($10,a1),d0
  458.         move.w    ($9E,a6),d1
  459.         eor.w    d1,d0
  460.         andi.w    #4,d0
  461.         beq.b    .F58
  462.         and.w    ($10,a1),d0
  463.         beq.b    .F58
  464.         movem.l    a2/a3,-(sp)
  465.         movea.l    a1,a2
  466.         movea.l    a1,a3
  467. .F2E        move.l    (a3),d0
  468.         beq.b    .F52
  469.         movea.l    d0,a3
  470.         move.w    ($20,a3),d0
  471.         move.w    #$2000,d1
  472.         and.w    d0,d1
  473.         beq.b    .F2E
  474.         move.w    #4,d1
  475.         and.w    d0,d1
  476.         beq.b    .F2E
  477.         movea.l    a2,a0
  478.         movea.l    a3,a1
  479.         jsr    (_LVOMakeVPort,a6)
  480.         bra.b    .F2E
  481. .F52        movea.l    a2,a1
  482.         movem.l    (sp)+,a2/a3
  483. .F58
  484.         move.l    a1,-(a7)        ;original
  485.         pea    (.ret,pc)
  486.         move.l    (8,a7),-(a7)
  487.         add.l    #-6-$57c0+$a586,(a7)
  488.         rts
  489.  
  490. .ret        addq.l    #8,a7
  491.         rts
  492.  
  493. gfx_SetFont    move.l    a0,d0
  494.         beq.b    .FAC
  495.         move.l    a1,d0
  496.         beq.b    .FAC
  497.         move.w    ($14,a0),($3a,a1)    ;original
  498.         rts
  499.  
  500. .FAC        addq.l    #4,a7
  501.         rts
  502.  
  503. gfx_SetSoftStyle
  504.         move.l    d2,-(sp)
  505.         moveq    #0,d2
  506.         movem.l    d0/d1/a0/a1,-(sp)
  507.         jsr    (_LVOAskSoftStyle,a6)
  508.         move.b    d0,d2
  509.         movem.l    (sp)+,d0/d1/a0/a1
  510.         movea.l    ($34,a1),a0
  511.         and.b    d2,d1
  512.         move.b    ($38,a1),d2
  513.         and.b    d1,d0
  514.         not.b    d1
  515.         and.b    d1,d2
  516.         or.b    d0,d2
  517.         move.b    d2,($38,a1)
  518.         or.b    ($16,a0),d2
  519.         move.l    d2,d0
  520.         move.l    (sp)+,d2
  521.         rts
  522.  
  523.     ENDC
  524.  
  525. ;============================================================================
  526.  
  527. disk_getunitid
  528.     IFLT NUMDRIVES
  529.         cmp.l    #1,d0            ;at least one drive
  530.         bcs    .set
  531.         cmp.l    (_custom1,pc),d0
  532.     ELSE
  533.         subq.l    #NUMDRIVES,d0
  534.     ENDC
  535. .set        scc    d0
  536.         ext.w    d0
  537.         ext.l    d0
  538.         rts
  539.  
  540. ;============================================================================
  541. ; kick13 does not provide fast and fine access to cia timers, therfore we
  542. ; use the rasterbeam, required minimum waiting is 75µs, one rasterline is
  543. ; 63.5µs a this results in min=127µs max=190.5µs
  544.  
  545. keyboard_start    or.b    #CIACRAF_SPMODE,(ciacra,a0)
  546.         clr.b    (ciasdr,a0)
  547.         lea    (_keyboarddelay,pc),a1
  548.         move.b    (_custom+vhposr),(a1)
  549.         rts
  550.  
  551. keyboard_end    move.w    (_keyboarddelay,pc),d1
  552.         lea    (_custom),a1
  553. .wait1        cmp.b    (vhposr,a1),d1
  554.         beq    .wait1
  555.         move.b    (vhposr,a1),d1
  556. .wait2        cmp.b    (vhposr,a1),d1
  557.         beq    .wait2
  558.         move.b    (vhposr,a1),d1
  559. .wait3        cmp.b    (vhposr,a1),d1
  560.         beq    .wait3
  561.         addq.l    #2,(a7)
  562.         and.b    #~(CIACRAF_SPMODE),(_ciaa+ciacra)
  563.         rts
  564.  
  565. ;============================================================================
  566.  
  567. timer_init    move.l    (_time,pc),a0
  568.         move.l    (whdlt_days,a0),d0
  569.         mulu    #24*60,d0
  570.         add.l    (whdlt_mins,a0),d0
  571.         move.l    d0,d1
  572.         lsl.l    #6,d0            ;*64
  573.         lsl.l    #2,d1            ;*4
  574.         sub.l    d1,d0            ;=*60
  575.         move.l    (whdlt_ticks,a0),d1
  576.         divu    #50,d1
  577.         ext.l    d1
  578.         add.l    d1,d0
  579.         move.l    d0,($c6,a2)
  580.         movem.l    (a7)+,d2/a2-a3        ;original
  581.         rts
  582.  
  583. ;============================================================================
  584.  
  585. trd_format
  586. trd_readwrite    movem.l    d2/a1-a2,-(a7)
  587.  
  588.         moveq    #0,d1
  589.         move.b    ($43,a3),d1        ;unit number
  590.         clr.b    (IO_ERROR,a1)
  591.  
  592.         btst    #1,($40,a3)        ;disk inserted?
  593.         beq    .diskok
  594.  
  595.         move.b    #TDERR_DiskChanged,(IO_ERROR,a1)
  596.  
  597. .end        movem.l    (a7),d2/a1-a2
  598.         bsr    trd_endio
  599.         movem.l    (a7)+,d2/a1-a2
  600.         moveq    #0,d0
  601.         move.b    (IO_ERROR,a1),d0
  602.         rts
  603.  
  604. .diskok        cmp.b    #CMD_READ,(IO_COMMAND+1,a1)
  605.         bne    .write
  606.  
  607. .read        moveq    #0,d2
  608.         move.b    (_trd_disk,pc,d1.w),d2    ;disk
  609.         move.l    (IO_OFFSET,a1),d0    ;offset
  610.         move.l    (IO_LENGTH,a1),d1    ;length
  611.         move.l    (IO_DATA,a1),a0        ;destination
  612.         move.l    (_resload,pc),a1
  613.         jsr    (resload_DiskLoad,a1)
  614.         bra    .end
  615.  
  616. .write        move.b    (_trd_prot,pc),d0
  617.         btst    d1,d0
  618.         bne    .protok
  619.         move.b    #TDERR_WriteProt,(IO_ERROR,a1)
  620.         bra    .end
  621.  
  622. .protok        lea    (.disk,pc),a0
  623.         move.b    (_trd_disk,pc,d1.w),d0    ;disk
  624.         add.b    #"0",d0
  625.         move.b    d0,(5,a0)        ;name
  626.         move.l    (IO_LENGTH,a1),d0    ;length
  627.         move.l    (IO_OFFSET,a1),d1    ;offset
  628.         move.l    (IO_DATA,a1),a1        ;destination
  629.         move.l    (_resload,pc),a2
  630.         jsr    (resload_SaveFileOffset,a2)
  631.         bra    .end
  632.  
  633. .disk        dc.b    "Disk.",0,0,0
  634.  
  635. _trd_disk    dc.b    1,2,3,4            ;number of diskimage in drive
  636. _trd_prot    dc.b    WPDRIVES        ;protection status
  637. _trd_chg    dc.b    0            ;diskchanged
  638.  
  639. trd_motor    moveq    #0,d0
  640.         bchg    #7,($41,a3)        ;motor status
  641.         seq    d0
  642.         rts
  643.  
  644. trd_protstatus    moveq    #0,d0
  645.         move.b    ($43,a3),d1        ;unit number
  646.         move.b    (_trd_prot,pc),d0
  647.         btst    d1,d0
  648.         seq    d0
  649.         move.l    d0,(IO_ACTUAL,a1)
  650.         add.l    #$a88-$a56-6,(a7)    ;skip unnecessary code
  651.         rts
  652.  
  653. trd_endio    move.l    (_expmem,pc),-(a7)    ;jump into rom
  654.         add.l    #$2a1b0,(a7)
  655.         rts
  656.  
  657. tdtask_cause    move.l    (_expmem,pc),-(a7)    ;jump into rom
  658.         add.l    #$29a68,(a7)
  659.         rts
  660.  
  661. trd_task
  662.     IFD DISKSONBOOT
  663.         bclr    #1,($40,a3)        ;set disk inserted
  664.         beq    .1
  665.         addq.l    #1,($126,a3)        ;inc change count
  666.         bsr    tdtask_cause
  667. .1
  668.     ENDC
  669.         move.b    ($43,a3),d1        ;unit number
  670.         lea    (_trd_chg,pc),a0
  671.         bclr    d1,(a0)
  672.         beq    .2            ;if not changed skip
  673.  
  674.         bset    #1,($40,a3)        ;set no disk inserted
  675.         bne    .3
  676.         addq.l    #1,($126,a3)        ;inc change count
  677.         bsr    tdtask_cause
  678. .3
  679.         bclr    #1,($40,a3)        ;set disk inserted
  680.         addq.l    #1,($126,a3)        ;inc change count
  681.         bsr    tdtask_cause
  682.  
  683. .2        rts
  684.  
  685.     IFD TRDCHANGEDISK
  686.     ;d0.b = unit
  687.     ;d1.b = new disk image number
  688. _trd_changedisk    movem.l    a6,-(a7)
  689.  
  690.         and.w    #3,d0
  691.         lea    (_trd_chg,pc),a0
  692.  
  693.         move.l    (4),a6
  694.         jsr    (_LVODisable,a6)
  695.  
  696.         move.b    d1,(-5,a0,d0.w)
  697.         bset    d0,(a0)
  698.  
  699.         jsr    (_LVOEnable,a6)
  700.  
  701.         movem.l    (a7)+,a6
  702.         rts
  703.     ENDC
  704.  
  705. ;============================================================================
  706.  
  707. dos_init    move.l    #$10001,d1
  708.         bra    _flushcache
  709.  
  710. dos_endcli    tst.l    D2            ;is -1 with EndCLI
  711.         bmi    .1
  712.         move.b    (a0,d2.l),d3        ;original
  713. .1        move.l    d3,d1            ;original
  714.         rts
  715.  
  716. dos_1        move.l    #$118,d1        ;original
  717.         bra    _flushcache
  718.  
  719. dos_LoadSeg    clr.l    (12,a1)            ;original
  720.         moveq    #12,d4            ;original
  721.         lea    (.savea4,pc),a6
  722.         move.l    a4,(a6)
  723.         lea    (.bcplend,pc),a6
  724.         rts
  725.  
  726. .savea4        dc.l    0
  727.  
  728. .bcplend    cmp.l    (.savea4,pc),a4        ;are we in dos_51?
  729.         beq    .end51
  730.         jmp    ($344a8-$344b4,a5)    ;call original
  731.  
  732. .end51        lea    ($344a8-$344b4,a5),a6    ;restore original
  733.     IFD CBDOSLOADSEG
  734.         movem.l    d0-a6,-(a7)
  735.         move.l    (a1),d0            ;d0 = BSTR FileName
  736.         tst.l    d1            ;d1 = BPTR SegList
  737.         beq    .failed
  738.         bsr    _cb_dosLoadSeg
  739. .failed        movem.l    (a7)+,d0-a6
  740.     ENDC
  741.         bsr    _flushcache
  742.         jmp    (a6)
  743.  
  744.     IFD BOOTDOS
  745. dos_bootdos
  746.  
  747.     ;init boot exe
  748.         lea    (_bootdos,pc),a3
  749.         move.l    a3,(bootfile_exe_j+2-_bootdos,a3)
  750.  
  751.     ;fake startup-sequence
  752.         lea    (bootname_ss_b,pc),a3    ;bstr
  753.         move.l    a3,d1
  754.  
  755.     ;return
  756.         rts
  757.  
  758.     ENDC
  759.  
  760. ;---------------
  761. ; performs a C:Assign
  762. ; IN:    A0 = CPTR destination name
  763. ;    A1 = CPTR directory (could be 0 meaning SYS:)
  764. ; OUT:    -
  765.  
  766.     IFD DOSASSIGN
  767. _dos_assign    movem.l    d2/a3-a6,-(a7)
  768.         move.l    a0,a3            ;A3 = name
  769.         move.l    a1,a4            ;A4 = directory
  770.         move.l    (4),a6
  771.  
  772.     ;backward compatibilty (given BSTR instead CPTR)
  773.         cmp.b    #" ",(a0)
  774.         bls    .skipname
  775.  
  776.     ;get length of name
  777.         moveq    #-1,d2
  778. .len        addq.l    #1,d2
  779.         tst.b    (a0)+
  780.         bne    .len
  781.  
  782.     ;get memory for name
  783.         move.l    d2,d0
  784.         addq.l    #2,d0            ;+ length and terminator
  785.         move.l    #MEMF_ANY,d1
  786.         jsr    (_LVOAllocMem,a6)
  787.     IFD DEBUG
  788.         tst.l    d0
  789.         beq    _debug3
  790.     ENDC
  791.         move.l    d0,a0
  792.         move.b    d2,(a0)+
  793. .cpy        move.b    (a3)+,(a0)+
  794.         bne    .cpy
  795.         move.l    d0,a3
  796. .skipname
  797.     ;get memory for node
  798.         move.l    #DosList_SIZEOF,d0
  799.         move.l    #MEMF_CLEAR,d1
  800.         jsr    (_LVOAllocMem,a6)
  801.     IFD DEBUG
  802.         tst.l    d0
  803.         beq    _debug3
  804.     ENDC
  805.         move.l    d0,a5            ;A5 = DosList
  806.  
  807.     ;open doslib
  808.         lea    (_dosname,pc),a1
  809.         jsr    (_LVOOldOpenLibrary,a6)
  810.         move.l    d0,a6
  811.  
  812.     ;lock directory
  813.         move.l    a4,d1
  814.         move.l    #ACCESS_READ,d2
  815.         jsr    (_LVOLock,a6)
  816.         move.l    d0,d1
  817.     IFD DEBUG
  818.         beq    _debug3
  819.     ENDC
  820.         lsl.l    #2,d1
  821.         move.l    d1,a0
  822.         move.l    (fl_Task,a0),(dol_Task,a5)
  823.         move.l    d0,(dol_Lock,a5)
  824.  
  825.     ;init structure
  826.         move.l    #DLT_DIRECTORY,(dol_Type,a5)
  827.         move.l    a3,d0
  828.         lsr.l    #2,d0
  829.         move.l    d0,(dol_Name,a5)
  830.  
  831.     ;add to the system
  832.         move.l    (dl_Root,a6),a6
  833.         move.l    (rn_Info,a6),a6
  834.         add.l    a6,a6
  835.         add.l    a6,a6
  836.         move.l    (di_DevInfo,a6),(dol_Next,a5)
  837.         move.l    a5,d0
  838.         lsr.l    #2,d0
  839.         move.l    d0,(di_DevInfo,a6)
  840.  
  841.         movem.l    (a7)+,d2/a3-a6
  842.         rts
  843.     ENDC
  844.  
  845. ;============================================================================
  846.  
  847.     IFD HDINIT
  848.  
  849. hd_init        sub.l    #$7e,a5                ;original
  850.  
  851.     INCLUDE    Sources:whdload/kickfs.s
  852.     
  853.     ENDC
  854.  
  855. ;============================================================================
  856.  
  857. _flushcache    move.l    (_resload,pc),-(a7)
  858.         add.l    #resload_FlushCache,(a7)
  859.         rts
  860.  
  861. ;============================================================================
  862.  
  863.     IFD DEBUG
  864. _debug1        tst    -1    ;unknown packet (=d2) for dos handler
  865. _debug2        tst    -2    ;no lock given for a_copy_dir (dos.DupLock)
  866. _debug3        tst    -3    ;error in _dos_assign
  867. _debug4        tst    -4    ;invalid lock specified
  868.         illegal        ;security if executed without mmu
  869.     ENDC
  870.  
  871. ;============================================================================
  872.  
  873. slv_kickname    dc.b    "33180.a500",0
  874. _keyboarddelay    dc.b    0
  875.     EVEN
  876. _tags        dc.l    WHDLTAG_CBSWITCH_SET
  877. _cbswitch_tag    dc.l    0
  878.         dc.l    WHDLTAG_ATTNFLAGS_GET
  879. _attnflags    dc.l    0
  880.         dc.l    WHDLTAG_MONITOR_GET
  881. _monitor    dc.l    0
  882.         dc.l    WHDLTAG_TIME_GET
  883. _time        dc.l    0
  884.     IFLT NUMDRIVES
  885.         dc.l    WHDLTAG_CUSTOM1_GET
  886. _custom1    dc.l    0
  887.     ENDC
  888.         dc.l    0
  889. _resload    dc.l    0
  890. _cbswitch_cop2lc    dc.l    0
  891.  
  892. ;============================================================================
  893.  
  894.     END
  895.